package com.kidback.bbloc259.ui.splash;

import android.view.LayoutInflater;
import android.view.View;

import com.kidback.bbloc259.app.KidApplication;
import com.kidback.bbloc259.databinding.PrivacyDialogBinding;
import com.kidback.bbloc259.ui.WebViewActivity;
import com.mylhyl.circledialog.BaseCircleDialog;
import com.mylhyl.circledialog.CircleDialog;

public class PrivacyDialog {

    private BaseCircleDialog dialog;

    private OnClickListener onClickListener;

    public PrivacyDialog(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnClickListener {
        void onYes();
        void onNo();
    }

    public void show() {

        PrivacyDialogBinding binding = PrivacyDialogBinding.inflate(LayoutInflater.from(KidApplication.getCompactActivity()), null, false);

        binding.tvLinkPrivate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebViewActivity.start(v.getContext(), "隐私政策", "https://www.kidback.top/BBLocationWeb/%E9%9A%90%E7%A7%81%E6%94%BF%E7%AD%96.html");
            }
        });

        binding.tvLinkUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebViewActivity.start(v.getContext(), "用户协议", "https://www.kidback.top/BBLocationWeb/%E7%94%A8%E6%88%B7%E5%8D%8F%E8%AE%AE.html");
            }
        });

        binding.btnNo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialog != null && dialog.isAdded()) {
                    dialog.dismiss();
                }
                onClickListener.onNo();
            }
        });

        binding.btnYes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickListener.onYes();

                if (dialog != null && dialog.isAdded()) {
                    dialog.dismiss();
                }
            }
        });

        dialog = new CircleDialog.Builder()
                .setWidth(0.8f)
                .setBodyView(binding.getRoot())
                .setCancelable(false)
                .setCanceledOnTouchOutside(false)
                .show(KidApplication.getCompactActivity().getSupportFragmentManager());


    }

}
